package com.evil.enterprise.controller;

import com.evil.account.api.RemoteUserDepartmentService;
import com.evil.common.account.dto.user.department.DepartmentManagersReqDTO;
import com.evil.common.account.dto.user.department.DepartmentManagersRespDTO;
import com.evil.common.account.dto.user.department.DeptUsersReqDTO;
import com.evil.common.account.dto.user.department.UserDeptManageReqDTO;
import com.evil.common.core.entity.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户部门接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/user/department")
public class UserDepartmentController {

    private final RemoteUserDepartmentService remoteUserDepartmentService;

    /**
     * 配置部门主管
     *
     * @param userDeptManageReqDTO userDeptManageReqDTO
     * @return R
     */
    @PostMapping("/manager")
    public R<?> userDepartmentManager(@Validated @RequestBody UserDeptManageReqDTO userDeptManageReqDTO) {
        remoteUserDepartmentService.userDepartmentManager(userDeptManageReqDTO);
        return R.success();
    }

    /**
     * 部门负责人列表
     *
     * @param queryDepartmentManager queryDepartmentManager
     * @return R
     */
    @PostMapping("/manager/list")
    public R<DepartmentManagersRespDTO> departmentManagerList(@Validated @RequestBody DepartmentManagersReqDTO queryDepartmentManager) {
        return R.success(remoteUserDepartmentService.departmentManagerList(queryDepartmentManager));
    }

    /**
     * 部门批量删除用户
     *
     * @param deptUsersReqDTO deptUsersReqDTO
     * @return R
     */
    @PostMapping("/batch-delete")
    public R<?> deleteUserDepartmentBatch(@Validated @RequestBody DeptUsersReqDTO deptUsersReqDTO) {
        remoteUserDepartmentService.deleteUserDepartmentBatch(deptUsersReqDTO);
        return R.success();
    }

    /**
     * 部门批量新增用户
     *
     * @param deptUsersReqDTO deptUsersReqDTO
     * @return R
     */
    @PostMapping("/batch-add")
    public R<?> addUserDepartmentBatch(@Validated @RequestBody DeptUsersReqDTO deptUsersReqDTO) {
        remoteUserDepartmentService.addUserDepartmentBatch(deptUsersReqDTO);
        return R.success();
    }
}
